package es.deusto.ingenieria.aike.time;

import java.util.List;

import es.deusto.ingenieria.aike.csp.formulation.Constraint;
import es.deusto.ingenieria.aike.csp.formulation.Variable;

public class MinutesConstraint extends Constraint<Integer> {
	
	private Environment env;

	public MinutesConstraint(List<Variable<Integer>> variables, String name, Environment env){
		super(name, variables);
		this.env = env;
	}

	public boolean isSatisfied(Variable<Integer> variable, Integer value) {
		
		switch (Integer.valueOf(variable.getName()))
		{
		case 0: {
					if (!this.getVariables().get(1).hasValue())
					{
						return true;
					}
					else if (value*10+this.getVariables().get(1).getValue()<env.getMaxMinutes())
					{
						return true;
					}
				} break;
		case 1: {
					if (!this.getVariables().get(0).hasValue())
					{
						return true;
					}
					else if (this.getVariables().get(0).getValue()*10+value<env.getMaxMinutes())
					{
						return true;
					}
				} break;
		case 4: {
					if (!this.getVariables().get(5).hasValue())
					{
						return true;
					}
					else if (value*10+this.getVariables().get(5).getValue()<env.getMaxMinutes())
					{
						return true;
					}
				} break;
		case 5: {
					if (!this.getVariables().get(4).hasValue())
					{
						return true;
					}
					else if (this.getVariables().get(4).getValue()*10+value<env.getMaxMinutes())
					{
						return true;
					}
				}
		}
		return false;
	}
}